package com.zen.demo.common.util;

import com.zen.demo.sys.mapper.DictLangMapper;
import com.zen.demo.sys.mapper.UserMapper;
import com.zen.demo.sys.service.DictLangService;
import com.zen.demo.sys.service.UserService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author alexzshl
 * @since 2022/1/28 22:10
 */
@Component
public class SpringContentUtil implements ApplicationContextAware {
    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringContentUtil.context = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return context;
    }

    public static Object getBean(String name) {
        return context.getBean(name);
    }

    public static <T> T getBean(Class<T> clazz) {
        return context.getBean(clazz);
    }

    public static <T> T getBean(String name, Class<T> clazz) {
        return context.getBean(name, clazz);
    }

    public static UserMapper getUserMapper() {
        return getBean(UserMapper.class);
    }

    public static UserService getUserService() {
        return getBean(UserService.class);
    }

    public static DictLangMapper getDictLangMapper() {
        return getBean(DictLangMapper.class);
    }
    public static DictLangService getDictLangService() {
        return getBean(DictLangService.class);
    }

}
